package test.kit.hutool._6_annotation;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum MyEnum {

    T1(-1, "数据不存在", 1),
    T2(1, "切割中", 1),
    T3(2, "识别成功", 1),
    T4(3, "考号重复", 1),
    T5(4, "不在报名表内", 1),
    T6(5, "识别失败", 1),
    T7(6, "匹配失败", 1),
    T8(7, "页码识别失败", 1),
    T9(8, "图片和考场不符", 1),
    T10(9, "匹配失败和页码识别失败", 1),
    T11(10, "空白页", 1);

    /* 三方返回 */
    private int code;
    private String desc;

    /* 本地状态 */
    private int status;

    MyEnum(int code, String desc, int status) {
        this.code = code;
        this.desc = desc;
        this.status = status;
    }

    /**
     * 根据code获取枚举
     */
    public static MyEnum getByCode(int code) {
        MyEnum myEnum = null;
        for (MyEnum e : MyEnum.values()) {
            if (e.code == code) {
                myEnum = e;
                break;
            }
        }
        if (myEnum == null) {
            throw new RuntimeException(StrUtil.format("未获取到 {} 枚举值", code));
        }
        return myEnum;
    }

    /**
     * 是否是最终状态
     */
    public boolean isFinal() {
        log.info("{}", this.code);
        return true;
    }

    @Override
    public String toString() {
        return StrUtil.format("code= {}, desc= {}, status= {}", code, desc, status);
    }
}
